package com.jl.jlapp.mvp.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.jl.jlapp.R;
import com.jl.jlapp.adapter.GoodsDetailPageAdapter;
import com.jl.jlapp.eneity.GoodsDetailModel;
import com.jl.jlapp.eneity.GoodsDetailModel.ResultDataBean;
import com.jl.jlapp.eneity.GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean;
import com.jl.jlapp.eneity.PostModel;
import com.jl.jlapp.mvp.fragment.GoodsDetailFragment;
import com.jl.jlapp.mvp.fragment.GoodsEvaluationFragment;
import com.jl.jlapp.mvp.fragment.GoodsMsgFragment;
import com.jl.jlapp.mvp.fragment.GoodsMsgFragment.SetOnClickLookGoodsSpec;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.popu.GoodsDetailActivityChooseGoodsSpecPopu;
import com.jl.jlapp.popu.GoodsDetailActivityChooseGoodsSpecPopu.OnClickOkBtnListener;
import com.jl.jlapp.utils.Tools;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

import java.util.ArrayList;
import java.util.List;

public class GoodsDetailActivity
        extends FragmentActivity
        implements GoodsMsgFragment.SetOnClickLookGoodsSpec, OnClickListener, OnCheckedChangeListener, GoodsDetailActivityChooseGoodsSpecPopu.OnClickOkBtnListener {
    public Integer activityId;
    public String activityName;
    public double compositeScores = 0.0D;
    public Integer discrepancyEvalNum = Integer.valueOf(0);
    FragmentManager fragmentManager;
    List<Fragment> fragments;
    int fromPage = -1;
    public Integer goodEvalNum = Integer.valueOf(0);
    public Double goodEvaluationRating = Double.valueOf(0.0D);
    GoodsDetailActivityChooseGoodsSpecPopu goodsDetailActivityChooseGoodsSpecPopu;
    GoodsDetailModel.ResultDataBean goodsDetailDataBean;
    Fragment goodsDetailFragment;
    GoodsDetailPageAdapter goodsDetailPageAdapter;
    @BindView(R.id.goods_detail_rela)
    RelativeLayout goodsDetailRela;
    Fragment goodsEvaluationFragment;
    public Integer goodsId = Integer.valueOf(0);
    Fragment goodsMsgFragment;
    @BindView(R.id.goods_msg_top_detail_radiobutton)
    RadioButton goodsMsgTopDetailRadiobutton;
    @BindView(R.id.goods_msg_top_evaluation_radiobutton)
    RadioButton goodsMsgTopEvaluationRadiobutton;
    @BindView(R.id.goods_msg_top_goods_radiobutton)
    RadioButton goodsMsgTopGoodsRadiobutton;
    @BindView(R.id.goods_msg_top_radiogroup)
    RadioGroup goodsMsgTopRadiogroup;
    public Integer goodsSpecificationId = Integer.valueOf(0);
    public Integer hasPicNum = Integer.valueOf(0);
    Integer isCheckBuyNowOrAddShopCart = Integer.valueOf(0);
    public Integer middleEvalNum = Integer.valueOf(0);
    List<RadioButton> radioButtons;
    public GoodsDetailModel.ResultDataBean resultDataBeanMsg = null;
    @BindView(R.id.return_img)
    ImageView returnImg;
    @BindView(R.id.search_goods_detail_error)
    TextView searchGoodsDetailError;
    @BindView(R.id.shop_detail_avtivity_center_view_pager)
    ViewPager shopDetailAvtivityCenterViewPager;
    FragmentTransaction transaction;
    @BindView(R.id.tv_add_shop_cart)
    TextView tvAddShopCart;
    @BindView(R.id.tv_buy_now)
    TextView tvBuyNow;
    @BindView(R.id.tv_contact_service)
    TextView tvContactservice;
    @BindView(R.id.tv_shop_cart)
    TextView tvShopCart;
    int userId = 0;

    private void getHasStrockGoods() {
        new ArrayList();
        int j;
        for (int i = 0; i < this.goodsDetailDataBean.getGoodsSpecificationDetails().size(); i = j + 1) {
            j = i;
            if (this.goodsDetailDataBean.getZeroStock() == 0) {
                j = i;
                if (((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsDetailDataBean.getGoodsSpecificationDetails().get(i)).getGxcGoodsState() == 2) {
                    j = i;
                    if (((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsDetailDataBean.getGoodsSpecificationDetails().get(i)).getGxcGoodsStock() <= 0) {
                        this.goodsDetailDataBean.getGoodsSpecificationDetails().remove(i);
                        j = i - 1;
                    }
                }
            }
        }
    }

    private void setData() {
        this.radioButtons = new ArrayList();
        this.radioButtons.add(this.goodsMsgTopGoodsRadiobutton);
        this.radioButtons.add(this.goodsMsgTopDetailRadiobutton);
        this.radioButtons.add(this.goodsMsgTopEvaluationRadiobutton);
        if (this.goodsMsgFragment == null) {
            this.goodsMsgFragment = new GoodsMsgFragment();
        }
        if (this.goodsDetailFragment == null) {
            this.goodsDetailFragment = new GoodsDetailFragment();
        }
        if (this.goodsEvaluationFragment == null) {
            this.goodsEvaluationFragment = new GoodsEvaluationFragment();
        }
        this.fragments = new ArrayList();
        this.fragments.add(this.goodsMsgFragment);
        this.fragments.add(this.goodsDetailFragment);
        this.fragments.add(this.goodsEvaluationFragment);
        this.goodsDetailPageAdapter = new GoodsDetailPageAdapter(getSupportFragmentManager(), this.fragments);
        this.shopDetailAvtivityCenterViewPager.setAdapter(this.goodsDetailPageAdapter);
        this.shopDetailAvtivityCenterViewPager.setCurrentItem(0);
        Drawable localDrawable1 = getResources().getDrawable(R.drawable.line_green_s);
        Drawable localDrawable2 = getResources().getDrawable(R.drawable.line_white_s);
        this.goodsMsgTopGoodsRadiobutton.setTextColor(getResources().getColor(R.color.checkGreenColor));
        this.goodsMsgTopGoodsRadiobutton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable1);
        this.goodsMsgTopGoodsRadiobutton.setChecked(true);
        this.goodsMsgTopDetailRadiobutton.setChecked(false);
        this.goodsMsgTopDetailRadiobutton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable2);
        this.goodsMsgTopDetailRadiobutton.setTextColor(getResources().getColor(R.color.trans_333333));
        this.goodsMsgTopEvaluationRadiobutton.setChecked(false);
        this.goodsMsgTopEvaluationRadiobutton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable2);
        this.goodsMsgTopEvaluationRadiobutton.setTextColor(getResources().getColor(R.color.trans_333333));
        this.shopDetailAvtivityCenterViewPager.addOnPageChangeListener(new OnPageChangeListener() {
            public void onPageScrollStateChanged(int paramAnonymousInt) {
            }

            public void onPageScrolled(int paramAnonymousInt1, float paramAnonymousFloat, int paramAnonymousInt2) {
            }

            public void onPageSelected(int paramAnonymousInt) {
                Log.d("aaaaaGoods", "position:" + paramAnonymousInt);
                Drawable localDrawable1 = GoodsDetailActivity.this.getResources().getDrawable(R.drawable.line_green_s);
                Drawable localDrawable2 = GoodsDetailActivity.this.getResources().getDrawable(R.drawable.line_white_s);
                if (paramAnonymousInt == 0) {
                    GoodsDetailActivity.this.goodsMsgTopGoodsRadiobutton.setTextColor(GoodsDetailActivity.this.getResources().getColor(R.color.checkGreenColor));
                    GoodsDetailActivity.this.goodsMsgTopGoodsRadiobutton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable1);
                    GoodsDetailActivity.this.goodsMsgTopGoodsRadiobutton.setChecked(true);
                    GoodsDetailActivity.this.goodsMsgTopDetailRadiobutton.setChecked(false);
                    GoodsDetailActivity.this.goodsMsgTopDetailRadiobutton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable2);
                    GoodsDetailActivity.this.goodsMsgTopDetailRadiobutton.setTextColor(GoodsDetailActivity.this.getResources().getColor(R.color.trans_333333));
                    GoodsDetailActivity.this.goodsMsgTopEvaluationRadiobutton.setChecked(false);
                    GoodsDetailActivity.this.goodsMsgTopEvaluationRadiobutton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable2);
                    GoodsDetailActivity.this.goodsMsgTopEvaluationRadiobutton.setTextColor(GoodsDetailActivity.this.getResources().getColor(R.color.trans_333333));
                } else if (paramAnonymousInt == 1) {
                    GoodsDetailActivity.this.goodsMsgTopDetailRadiobutton.setTextColor(GoodsDetailActivity.this.getResources().getColor(R.color.checkGreenColor));
                    GoodsDetailActivity.this.goodsMsgTopDetailRadiobutton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable1);
                    GoodsDetailActivity.this.goodsMsgTopDetailRadiobutton.setChecked(true);
                    GoodsDetailActivity.this.goodsMsgTopGoodsRadiobutton.setChecked(false);
                    GoodsDetailActivity.this.goodsMsgTopGoodsRadiobutton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable2);
                    GoodsDetailActivity.this.goodsMsgTopGoodsRadiobutton.setTextColor(GoodsDetailActivity.this.getResources().getColor(R.color.trans_333333));
                    GoodsDetailActivity.this.goodsMsgTopEvaluationRadiobutton.setChecked(false);
                    GoodsDetailActivity.this.goodsMsgTopEvaluationRadiobutton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable2);
                    GoodsDetailActivity.this.goodsMsgTopEvaluationRadiobutton.setTextColor(GoodsDetailActivity.this.getResources().getColor(R.color.trans_333333));
                } else {
                    GoodsDetailActivity.this.goodsMsgTopEvaluationRadiobutton.setTextColor(GoodsDetailActivity.this.getResources().getColor(R.color.checkGreenColor));
                    GoodsDetailActivity.this.goodsMsgTopEvaluationRadiobutton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable1);
                    GoodsDetailActivity.this.goodsMsgTopEvaluationRadiobutton.setChecked(true);
                    GoodsDetailActivity.this.goodsMsgTopGoodsRadiobutton.setChecked(false);
                    GoodsDetailActivity.this.goodsMsgTopGoodsRadiobutton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable2);
                    GoodsDetailActivity.this.goodsMsgTopGoodsRadiobutton.setTextColor(GoodsDetailActivity.this.getResources().getColor(R.color.trans_333333));
                    GoodsDetailActivity.this.goodsMsgTopDetailRadiobutton.setChecked(false);
                    GoodsDetailActivity.this.goodsMsgTopDetailRadiobutton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable2);
                    GoodsDetailActivity.this.goodsMsgTopDetailRadiobutton.setTextColor(GoodsDetailActivity.this.getResources().getColor(R.color.trans_333333));
                }

            }
        });
    }

    public void OnClickOkBtn(Integer paramInteger1, Integer paramInteger2, Integer paramInteger3, Integer paramInteger4) {
        this.goodsDetailActivityChooseGoodsSpecPopu.dismiss();
        if (this.isCheckBuyNowOrAddShopCart.intValue() == 0) {
            insertShoppingCart(Integer.valueOf(this.userId), paramInteger1, paramInteger2, paramInteger3);
            return;
        }
        Intent localIntent = new Intent(this, OrderSubmitActivity.class);
        localIntent.putExtra("isFromWhichPage", 1);
        localIntent.putExtra("buyNum", paramInteger3);
        localIntent.putExtra("goodsSpecId", paramInteger2);
        localIntent.putExtra("goodsId", paramInteger1);
        localIntent.putExtra("isPresell", paramInteger4);
        if (paramInteger4.intValue() == 1) {
            localIntent.putExtra("activityId", this.activityId);
        }
        startActivity(localIntent);
    }

    public void getGoodsDetailMsgByGoodsId() {
        Net.get().getGoodsDetailMsgByGoodsId(this.goodsId.intValue()).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).
                subscribe(new CommonObserver<GoodsDetailModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(GoodsDetailModel goodsDetailModel) {

                    }
                });
    }

    public void insertShoppingCart(Integer paramInteger1, Integer paramInteger2, Integer paramInteger3, Integer paramInteger4) {
        Net.get().insertShoppingCart(paramInteger1.intValue(), paramInteger2.intValue(), paramInteger3.intValue(), paramInteger4.intValue(), this.activityId.intValue(), this.activityName)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CommonObserver<PostModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(PostModel postModel) {

                    }
                });
    }

    @Override
    public void onCheckedChanged(RadioGroup paramRadioGroup, int paramInt) {
//        int i = paramRadioGroup.gechild;
//        paramRadioGroup.childa
        int i=0;
        if (((RadioButton) this.radioButtons.get(i)).getId() == paramInt) {

            ((RadioButton) this.radioButtons.get(i)).setTextColor(getResources().getColor(R.color.checkGreenColor));
            Drawable drawable = getResources().getDrawable(R.drawable.line_green_s);
            ((RadioButton) this.radioButtons.get(i)).setCompoundDrawablesWithIntrinsicBounds(null, null, null, drawable);
            ((RadioButton) this.radioButtons.get(i)).setChecked(true);

        } else {
            Drawable drawable = getResources().getDrawable(R.drawable.line_white_s);
            ((RadioButton) this.radioButtons.get(i)).setChecked(false);
            ((RadioButton) this.radioButtons.get(i)).setCompoundDrawablesWithIntrinsicBounds(null, null, null, drawable);
            ((RadioButton) this.radioButtons.get(i)).setTextColor(getResources().getColor(R.color.trans_333333));
        }
        switch (i) {
            case 0:
                this.shopDetailAvtivityCenterViewPager.setCurrentItem(0);
                break;

            case 1:
                this.shopDetailAvtivityCenterViewPager.setCurrentItem(1);

                break;
            case 2:
                this.shopDetailAvtivityCenterViewPager.setCurrentItem(2);

                break;
            case 3:
                break;
            default:
                break;
        }

    }

    public void onClick(View paramView) {
        switch (paramView.getId()) {
            default:
                break;
            case R.id.return_img:
                if (this.fromPage == -1) {
                    finish();
                    return;
                }
                Intent intent = new Intent(this, BaseActivity.class);
                startActivity(intent);
                finish();
                break;
            case R.id.tv_contact_service:
                if (this.userId > 0) {
                    startActivity(new Intent(this, CustomerServiceActivity.class));
                    return;
                }
                Toast.makeText(this, "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
                startActivity(new Intent(this, LoginActivity.class));
                return;
            case R.id.tv_shop_cart:
                if (this.userId > 0) {
                    Intent intentMain = new Intent(this, BaseActivity.class);
                    intentMain.putExtra("shouldReplaceFragment", 2);
                    startActivity(intentMain);
                    return;
                }
                Toast.makeText(this, "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
                startActivity(new Intent(this, LoginActivity.class));
                return;
            case R.id.tv_add_shop_cart:
                if (this.userId > 0) {
                    this.isCheckBuyNowOrAddShopCart = Integer.valueOf(0);
                    Log.d("aaaaaaagd", "length:" + this.goodsDetailDataBean.getGoodsSpecificationDetails().size() + " 值：" + ((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsDetailDataBean.getGoodsSpecificationDetails().get(0)).getSpecifications());
                    this.goodsDetailActivityChooseGoodsSpecPopu = new GoodsDetailActivityChooseGoodsSpecPopu(this, ((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsDetailDataBean.getGoodsSpecificationDetails().get(0)).getSpecifications(), this.goodsDetailDataBean);
                    this.goodsDetailActivityChooseGoodsSpecPopu.showAtLocation(findViewById(R.id.goods_msg_page), 80, 0, 0);
                    this.goodsDetailActivityChooseGoodsSpecPopu.setOnClickOkBtnListener(this);
                    return;
                }
                Toast.makeText(this, "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
                startActivity(new Intent(this, LoginActivity.class));
                return;
        }
        if (this.userId > 0) {
            this.isCheckBuyNowOrAddShopCart = Integer.valueOf(1);
            Tools.addActivity(this);
            this.goodsDetailActivityChooseGoodsSpecPopu = new GoodsDetailActivityChooseGoodsSpecPopu(this, ((GoodsDetailModel.ResultDataBean.GoodsSpecificationDetailsBean) this.goodsDetailDataBean.getGoodsSpecificationDetails().get(0)).getSpecifications(), this.goodsDetailDataBean);
            this.goodsDetailActivityChooseGoodsSpecPopu.showAtLocation(findViewById(R.id.goods_msg_page), 80, 0, 0);
            this.goodsDetailActivityChooseGoodsSpecPopu.setOnClickOkBtnListener(this);
            return;
        }
        Toast.makeText(this, "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(this, LoginActivity.class));
    }

    public void onClickLookEvaluation() {
        int i = 0;
        if (i < this.radioButtons.size()) {
            Drawable localDrawable;
            if (i == 2) {
                ((RadioButton) this.radioButtons.get(i)).setTextColor(getResources().getColor(R.color.checkGreenColor));
                localDrawable = getResources().getDrawable(R.drawable.line_green_s);
                ((RadioButton) this.radioButtons.get(i)).setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable);
                ((RadioButton) this.radioButtons.get(i)).setChecked(true);
            }
            for (; ; ) {
                i += 1;
                localDrawable = getResources().getDrawable(R.drawable.line_white_s);
                ((RadioButton) this.radioButtons.get(i)).setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable);
                ((RadioButton) this.radioButtons.get(i)).setTextColor(getResources().getColor(R.color.trans_333333));
                ((RadioButton) this.radioButtons.get(i)).setChecked(false);
            }
        }
        this.shopDetailAvtivityCenterViewPager.setCurrentItem(2);
    }

    public void onClickLookGoodsSpec() {
        int i = 0;
        if (i < this.radioButtons.size()) {
            Drawable localDrawable;
            if (i == 1) {
                ((RadioButton) this.radioButtons.get(i)).setTextColor(getResources().getColor(R.color.checkGreenColor));
                localDrawable = getResources().getDrawable(R.drawable.line_green_s);
                ((RadioButton) this.radioButtons.get(i)).setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable);
                ((RadioButton) this.radioButtons.get(i)).setChecked(true);
            }
            for (; ; ) {
                i += 1;
                localDrawable = getResources().getDrawable(R.drawable.line_white_s);
                ((RadioButton) this.radioButtons.get(i)).setCompoundDrawablesWithIntrinsicBounds(null, null, null, localDrawable);
                ((RadioButton) this.radioButtons.get(i)).setTextColor(getResources().getColor(R.color.trans_333333));
                ((RadioButton) this.radioButtons.get(i)).setChecked(false);
            }
        }
        this.shopDetailAvtivityCenterViewPager.setCurrentItem(1);
    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_goods_detail);
        ButterKnife.bind(this);
    }

    public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent) {
        if (paramInt == 4) {
            if (this.fromPage == -1) {
                finish();
            }else {
                Intent localIntent = new Intent(this, BaseActivity.class);
                startActivity(localIntent);
                finish();
            }
        }

        return super.onKeyDown(paramInt, paramKeyEvent);
    }

    protected void onResume() {
        super.onResume();
        this.userId = getSharedPreferences("JLAppData", 0).getInt("userId", 0);
        Intent localIntent = getIntent();
        this.goodsId = Integer.valueOf(localIntent.getIntExtra("goodsId", 0));
        this.activityId = Integer.valueOf(localIntent.getIntExtra("activityId", 0));
        this.fromPage = localIntent.getIntExtra("isFromScreenActivity", -1);
        if (this.activityId.intValue() > 0) {
        }
        for (this.activityName = localIntent.getStringExtra("activityName"); ; this.activityName = "") {
            getGoodsDetailMsgByGoodsId();
            setClickListener();
            return;
        }
    }

    public void setClickListener() {
        this.goodsMsgTopRadiogroup.setOnCheckedChangeListener(this);
        this.returnImg.setOnClickListener(this);
        this.tvContactservice.setOnClickListener(this);
        this.tvShopCart.setOnClickListener(this);
        this.tvAddShopCart.setOnClickListener(this);
        this.tvBuyNow.setOnClickListener(this);
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/GoodsDetailActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */